//
//  LeaveWordView.m
//  phmall
//
//  Created by admin on 2017/12/21.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "LeaveWordView.h"

@implementation LeaveWordView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
        
        self.title=[[UILabel alloc]init];
        [self addSubview:self.title];
        self.title.font=[UIFont systemFontOfSize:15];
        self.title.text=Localized(@"留言");
       
        self.nameView=[[UIView alloc]init];
        self.nameView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self addSubview:self.nameView];
        
        self.nameLabel=[[UILabel alloc]init];
        self.nameLabel.text=[NSString stringWithFormat:@"%@*:",Localized(@"联系姓名")];
        self.nameLabel.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.nameLabel];
        
        self.name=[[UITextField alloc]init];
        self.name.placeholder=Localized(@"必填");
        self.name.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.name];
        
        self.phoneView=[[UIView alloc]init];
        self.phoneView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self addSubview:self.phoneView];
        
        self.phoneLabel=[[UILabel alloc]init];
        self.phoneLabel.text=[NSString stringWithFormat:@"%@*:",Localized(@"联系方式")];
        self.phoneLabel.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.phoneLabel];
        
        self.phone=[[UITextField alloc]init];
        self.phone.placeholder=Localized(@"必填");
        self.phone.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.phone];
        
        self.adderss=[[UITextField alloc]init];
        self.adderss.placeholder=Localized(@"必填");
        self.adderss.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.adderss];
        
        self.adderssView=[[UIView alloc]init];
        self.adderssView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self addSubview:self.adderssView];
        
        self.adderssLabel=[[UILabel alloc]init];
        self.adderssLabel.text=[NSString stringWithFormat:@"%@*:",Localized(@"联系地址")];
        self.adderssLabel.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.adderssLabel];
        
        self.message=[[EvaluateText alloc]init];
        self.message.placeholder=Localized(@"内容");
        self.message.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.message];
        
        self.messageView=[[UIView alloc]init];
        self.messageView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self addSubview:self.messageView];
        
        self.messageLabel=[[UILabel alloc]init];
        self.messageLabel.text=[NSString stringWithFormat:@"%@*:",Localized(@"留言内容")];
        self.messageLabel.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.messageLabel];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(0);
        make.height.offset(44);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.equalTo(self.title.mas_bottom).offset(0);
        make.height.offset(44);
    }];
    CGSize nameSize = [self.nameLabel.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(self.nameLabel);
        make.width.offset(SCREEN_WIDTH-nameSize.width-15);
    }];
    
    [self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(SCREEN_WIDTH-20);
        make.left.offset(10);
        make.height.offset(1);
        make.bottom.equalTo(self.nameLabel);
    }];
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(0);
        make.height.offset(44);
    }];

    CGSize phoneSize = [self.phoneLabel.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    
    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(self.phoneLabel);
        make.width.offset(SCREEN_WIDTH-phoneSize.width-15);
    }];

    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(SCREEN_WIDTH-20);
        make.left.offset(10);
        make.height.offset(1);
        make.bottom.equalTo(self.phoneLabel);
    }];

    [self.adderssLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.equalTo(self.phoneLabel.mas_bottom).offset(0);
        make.height.offset(44);
    }];
    CGSize adderssSize = [self.adderssLabel.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    [self.adderss mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(self.adderssLabel);
        make.width.offset(SCREEN_WIDTH-adderssSize.width-15);
    }];

    [self.adderssView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(SCREEN_WIDTH-20);
        make.left.offset(10);
        make.height.offset(1);
        make.bottom.equalTo(self.adderssLabel);
    }];
    
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.equalTo(self.adderssLabel.mas_bottom).offset(0);
        make.height.offset(44);
    }];

    [self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(SCREEN_WIDTH-20);
        make.left.offset(10);
        make.height.offset(1);
        make.bottom.equalTo(self.adderssLabel).offset(90);
    }];
    CGSize messageSize = [self.messageLabel.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;

    [self.message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.adderssView).offset(7);
        make.bottom.equalTo(self.messageView).offset(-4);
        make.width.offset(SCREEN_WIDTH-messageSize.width-5);
        make.left.offset(messageSize.width+0);
    }];
}

@end
